package com.cxl.autocode.create;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;

import com.summer.core.entity.Field;
import com.summer.core.entity.STable;

/**
 * 生成.java实现代码
 * @author Administrator
 *
 */
public class JspGeneratorImpl extends AbstractGenerator implements JspGenerator{

	public String listPage="template/list.jsp.ftl";
	public String addPage="template/input.jsp.ftl";
	
	public void getAddPage(List<Field> fields,STable table) {
		 Map<String, Object> data = new HashMap<String, Object>();
	     data.put("fields", fields);
	     data.put("table", table);
	     String filePath=new String("apps/jsp/"+package2path(table.getPath()+"/"+table.getName().toLowerCase()));
	     super.generate(addPage, data,  filePath+"/"+table.getName().toLowerCase()+"_input.jsp");
		
	}
	
	public void getListPage(List<Field> fields, STable table) {
		 Map<String, Object> data = new HashMap<String, Object>();
	     data.put("fields", fields);
	     data.put("table", table);
	     String filePath=new String("apps/jsp/"+package2path(table.getPath()+"/"+table.getName().toLowerCase()));
	     super.generate(listPage, data, filePath+"/"+table.getName().toLowerCase()+"_list.jsp");
		
	}
	
	
	public void getAddPage(ServletContext context,List<Field> fields,STable table) {
		 Map<String, Object> data = new HashMap<String, Object>();
	     data.put("fields", fields);
	     data.put("table", table);
	     String filePath=new String("apps/jsp/"+package2path(table.getPath()+"/"+table.getName().toLowerCase()));
	     super.generate(context,addPage, data,  filePath+"/"+table.getName().toLowerCase()+"_input.jsp");
		
	}
	
	public void getListPage(ServletContext context,List<Field> fields, STable table) {
		 Map<String, Object> data = new HashMap<String, Object>();
	     data.put("fields", fields);
	     data.put("table", table);
	     String filePath=new String("apps/jsp/"+package2path(table.getPath()+"/"+table.getName().toLowerCase()));
	     super.generate(context,listPage, data, filePath+"/"+table.getName().toLowerCase()+"_list.jsp");
		
	}
}
